import ACCESS_ENUM from "@/access/accessEnum";
import AccessEnum from "@/access/accessEnum";

const checkAccess = (loginUser: API.UserVo, access: any) => {
  const userRole = loginUser?.userRole;
  if (!access) return true;
  if (access === ACCESS_ENUM.NOT_LOGIN) {
    return true;
  }
  if (userRole) {
    //要求的是用户权限，未登录的时候返回出false
    if (access === ACCESS_ENUM.USER) {
      if (userRole === ACCESS_ENUM.NOT_LOGIN) {
        return false;
      }
      return true;
    }
    //要求的是管理权限， 用户权限和未登录的时候返回出false
    if (access === ACCESS_ENUM.ADMIN) {
      if (userRole === AccessEnum.ADMIN) {
        return true;
      }
      return false;
    }
  } else {
    return false;
  }
};
export default checkAccess;
